package cn.edu.szpt.mysimplemp3player.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cn.edu.szpt.mysimplemp3player.R;
import cn.edu.szpt.mysimplemp3player.beans.MusicBean;

public class MusicListAdapter extends RecyclerView.Adapter<MusicListAdapter.ViewHolder> {
    private Context context;
    private List<MusicBean> data;
    private int selectedItemPos = -1;  //记录选中项的Postion

    public void setSelectedItemPos(int selectedItemPos) {
        this.selectedItemPos = selectedItemPos;
        notifyDataSetChanged();
    }

    public MusicListAdapter(Context context, List<MusicBean> data) {
        this.context = context;
        this.data = data;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        LayoutInflater inflater =  LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.item_music,parent,false);
        ViewHolder holder = new ViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView item_imgShowPic;
        private TextView item_tvMusicName;
        private TextView item_tvMusicSinger;
        private TextView item_tvMusicDuration;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            item_imgShowPic = itemView.findViewById(R.id.item_imgShowpic);
            item_tvMusicName = itemView.findViewById(R.id.item_tvMusicName);
            item_tvMusicSinger = itemView.findViewById(R.id.item_tvMusicSinger);
            item_tvMusicDuration = itemView.findViewById(R.id.item_tvMusicDuration);
        }
    }
}
